This function wraps numerous Leaflet features into a single, well-parametrized interface.
Usage
robomap(
d,
area,
title = NULL,
subtitle = "",
caption = NULL,
hovertext = list(flag = "", unit = ""),
map_opacity = 0.9,
tile_opacity = 0.7,
map_palette = NULL,
border_width = getOption("roboplot.trace.border")$width,
height = getOption("roboplot.height"),
width = getOption("roboplot.width"),
legend = set_legend(),
data_contour = FALSE,
markers = FALSE,
rounding = round(getOption("roboplot.rounding")),
zoom = TRUE,
...
)Arguments
- d
Data frame. Data to be created a map from.
- area
Symbol or string. Variable from argument 'd' to use to identify the areas described by the map. This must be of class sfc_MULTIPOLYGON.
- title, subtitle
Characters. Labels for plot elements.
- caption
Function or character. Use a string, or
set_caption().- hovertext
List. Use a list with named characters flag and unit.
- map_opacity, tile_opacity
Numeric. Values from 0 to 1, defining how opaque the map polygon fill color or underlying map tiles are. 0 removes the tile layer, but retains the polygon borders if any.
- map_palette
Character or function. Must be hexadecimal colors or valid css colors, or use
set_heatmap()if specifying color breakpoints.- border_width
Integer. The width of polygon borders.
- height, width
Numeric. Height and width of the plot. Default width is NA. for responsive plots.
- legend
Function. Use
set_legend().- data_contour
Logical. Experimental. If TRUE,
robomap()will produce a contour-like representation of the data, which does not conform to the boundaries of the polygons. This provides a smoother transition and helps in visualizing general trends across regions. Default is FALSE.- markers
Logical. Experimental. Whether markers will be added on the map based on the columns "lat" and "lon". Default is FALSE.
- rounding
Numeric. How
robomap()rounds numeric values.- zoom
Logical. Whether the map is zoomable or not.
- ...
Placeholder for other parameters.
Examples
# You can use `robomap()` to create interactive maps. Note that very large
# number of map polygons makes for slow rendering maps.
vaesto_postinumeroittain |>
dplyr::filter(Alue == "Espoo") |>
robomap(Postinumeroalue, title = "V\u00e4kiluku Espoossa", caption = "Tilastokeskus")
# Default polygon colors are picked from trace colors set with
# `set_roboplot_options()` based on luminosity. Control polygon colors with
# `map_palette`. `robomap()` expands upon this as necessary.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4kiluku postinumeroittain",
subtitle = "Otanta",
caption = "Tilastokeskus",
map_palette = c("lightgreen", "darkred")
)
# You might want to disallow zooming for some reason. The map will be draggable,
# but zoom by buttons or scrolling is disabled.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
subtitle = "Otanta",
caption = "Tilastokeskus",
zoom = FALSE
)
# Other controls you might need.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = c("lightgreen", "darkred"),
border_width = 2,
tile_opacity = 0.2,
map_opacity = 0.5
)
# Control the story you want to tell by using `set_heatmap()` with `map_palette`,
# setting the colors and breakpoints. Use `legend` with `set_legend(breaks)`
# to control how many entries the legend is split to.
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = set_heatmap(
midvalue = 6000,
midcolor = "yellow",
maxcolor = "red"
),
legend = set_legend(breaks = 3),
map_opacity = 1,
border_width = 0
)
# Or just give the legend breaks
vaesto_postinumeroittain |>
robomap(
Postinumeroalue,
title = "V\u00e4est\u00f6 postinumeroittain",
caption = "Tilastokeskus",
map_palette = set_heatmap(midvalue = 6000, midcolor = "yellow", maxcolor = "red"),
legend = set_legend(breaks = c(3000, 6000, 9000)),
map_opacity = 1,
border_width = 0
)